package estadistica;

import java.util.Random;

//distribucion poisson:
// ======================
//
// f(t) = L*e^(-L*t)  , t > 0, L es la tasa de ocurrencia de un evento.
//
// L = 1/Mú
//
// r = F(t) = 1 - e^(-L*t)
// r = e^(-L*t)
// t = (1/L)*ln(1/r)   ==> -(1/L)*ln(r)
//
// r es un numero aleatorio con distribucion equiprobable entre 0 y 1.
//

public class PoissonEventGenerator {
	
	private double lambda;
	private double lastEventTime;
	private Random randomizer;
	
	public PoissonEventGenerator(double lambda) {
		this.lambda = lambda;
		this.lastEventTime = 0.00;
		this.randomizer = new Random(System.currentTimeMillis());
	}
	
	public Double getNextEventTime() {
		double randNum = this.randomizer.nextDouble(); 
		double deltaEventTime = (-1.00/this.lambda) * Math.log(randNum);
		this.lastEventTime += deltaEventTime;
		
		return this.lastEventTime;
	}

	public void reset() {
		this.lastEventTime = 0.00;
	}
}
